<html>
	<head>
		<meta charset='utf-8'>
		<title>Age Calculator</title>
		<script type="text/javascript">
			function calculator(birth){
				var aBirth=birth.split("/");
				var date = new Date();
				var day=date.getDate();
				var month= date.getMonth()+1;
				var year = date.getFullYear();

				if(aBirth[1]<=month){
					if(aBirth[0]>=day){
						var age= parseInt(year)-parseInt(aBirth[2]);
					}else{
						var age= (parseInt(year)-parseInt(aBirth[2]))-1;
					}
				}else{
					var age= (parseInt(year)-parseInt(aBirth[2]));
				}

				alert("Tu edad actual es: "+age+" años");
			}
		</script>
		<style type="text/css">
			html,body{
    			height: 100%;
			}
			body{
			   	display: table; 
   				margin: 0 auto;
			}
			div.Principal{
				display: table-cell;   
    			vertical-align: middle;
			}
		</style>
	</head>
	<body>
		<div class='principal'>
			<h1>Calculadora de edad</h1>
			<form>
				<label>¿En qué fecha naciste? </label>
				<input type='date' id='birth' value=''><br><br>
				<input type='button' value='¡Calcular!' onClick="calculator(document.getElementById('birth').value);">
			</form>
		</div>
	</body>
</html>